<?php
/**
 * @brief 控制器基类
 */
class Controller extends Yaf_Controller_Abstract {
    public $middlewares = []; // 中间件列表

    public static $server;    // Http请求相关的服务器信息，相当于PHP的$_SERVER数组
    public static $header;    // Http请求的头部信息
    public static $get;       // Http请求的GET参数，相当于PHP中的$_GET数组
    public static $post;      // Http请求的POST参数，相当于PHP中的$_POST数组
    public static $request;   // Http请求的REQUEST参数，相当于PHP中的$_REQUEST数组
    public static $cookie;    // Http请求携带的COOKIE信息，格式为键值对数组
    public static $files;     // 文件上传信息，相当于PHP中的$_FILES数组
    
    /**
     * 初始化
     * 
     * @return void
     */
    public function init() {
        self::$server = Http_Server::$server;
        self::$header = Http_Server::$header;
        self::$get = Http_Server::$get;
        self::$post = Http_Server::$post;
        self::$request = Http_Server::$request;
        self::$cookie = Http_Server::$cookie;
        self::$files = Http_Server::$files;

		// 多语言设置
        $config = Yaf_Registry::get('Config');
		if ($config->app->multi_lang) {
        	if (Session::getSessId()) {
				$lang = I18n::getLang();
                if (!$lang) $lang = $config->app->default_lang;
				I18n::setLang($lang);
			}
		}
        
        // 中间件处理
        if ($this->middlewares) {
            Middleware::getInstance()->handle($this->middlewares);
        }
    }
}
